<template>
  <div style="background: #fff;padding-bottom: 50px;">
    <div class="index-top">
      <div class="index-bg">
        <img src="../../../assets/images/index_bg.png" style="width: 100%;">
      </div>
      <vTitle page="1"></vTitle>
      <div class="index-banner">
        <swiper loop auto :show-desc-mask="false" :list="demo06_list" :index="demo06_index" @on-index-change="demo06_onIndexChange" style="border-radius: 5px;"></swiper>
      </div>
    </div>
    <!--图标按钮-->
    <div class="icon-nav">
      <ul>
        <li class="icon-nav-item" v-for="(item,index) in iconList" :key="index">
          <a>
            <img :src="item.img">
            <p>{{item.text}}</p>
          </a>
        </li>
      </ul>
    </div>
    <!--广告-->
    <div>
      <img src="../../../assets/images/index_adv1.png">
    </div>
    <!--超值特卖-->
    <div class="bargain-sale">
      <img src="../../../assets/images/index_adv2.png">
      <flexbox style="width: 95%;margin: 0 auto;" :gutter="12">
        <flexbox-item>
          <div class="flex-demo flex-left">
            <div class="right-item0">
              <h4 class="flex-title">进口水果</h4>
              <p class="flex-text">越南白心火龙果，白色果肉</p>
              <div class="flex-btn">GO <i class="iconfont icon-xiayiye"></i></div>
            </div>
          </div>
        </flexbox-item>
        <flexbox-item>
          <flexbox orient="vertical" :gutter="12">
            <flexbox-item><div class="flex-demo flex-right">
              <div class="right-item">
                <h4 class="flex-title">特价蔬菜</h4>
                <p class="flex-text">蔬菜特价批发</p>
                <div class="flex-btn right">GO <i class="iconfont icon-xiayiye"></i></div>
              </div>
            </div></flexbox-item>
            <flexbox-item><div class="flex-demo">
              <div class="right-item2">
                <h4 class="flex-title">特价蔬菜</h4>
                <p class="flex-text">蔬菜特价批发</p>
                <div class="flex-btn right">GO <i class="iconfont icon-xiayiye"></i></div>
              </div>
            </div></flexbox-item>
          </flexbox>
        </flexbox-item>
      </flexbox>
    </div>
    <!--bar-->
    <div>
      <tab :line-width="2" custom-bar-width="60px" active-color="#33bb99" v-if="isShow">
        <tab-item selected @click.native="changeTab(true,item)">全部</tab-item>
        <tab-item :selected="tabIndex==index?true:false" v-for="(item,index) in tabList" :key="index" @click.native="changeTab(false,item)">{{item.classification_name}}</tab-item>
      </tab>
      <div class="goods-item" v-if="isShow" v-for="(item,index) in goodsList" :key="index">
        <div class="goods-item-title">
          <span class="title">{{item.classification_name}}</span>
          <span class="more" @click="toMore">更多 <i class="iconfont icon-xiayiye"></i></span>
        </div>
        <div class="goods-text">
          <ul>
            <li class="search-item" v-for="(item2,index2) in item.goodsList" :key="index2">
              <div class="item-text">
                <div class="item-img" @click="showDetail(item2)">
                  <img :src="config1.fileUrl+item2.imgList[0].img_url">
                </div>
                <p @click="showDetail(item2)">{{item2.goods_name}}</p>
                <div class="item-tip">
                  <span>销量：{{item2.sales_num}}</span>
                  <i class="iconfont icon-dianpu" @click="toShop(item2)"></i>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div v-transfer-dom>
      <popup v-model="isShowDetail" height="100%">
        <vTitle page="3" @transferUser="back" v-bind:title="'商品详情'"></vTitle>
        <vDetail v-if="isShowDetail" v-bind:goodsId="goodsId" v-bind:state="isShowDetail"></vDetail>
      </popup>
    </div>
    <div v-transfer-dom>
      <popup v-model="isStore" height="100%" style="background: #fbf9fe">
        <vTitle page="2" @transferUser="back1"></vTitle>
        <vStore v-if="isStore" v-bind:text="text" v-bind:type="type"></vStore>
      </popup>
    </div>
    <toast v-model="showPositionValue" type="text" :time="1000" is-show-mask :text="toastMsg" :position="position"></toast>
  </div>
</template>
<script>
  import vTitle from './Title'
  import vDetail from './Detail'
  import vStore from './Store'
  import { XHeader, Swiper, Flexbox, FlexboxItem, Tab, TabItem, Grid, GridItem, Popup, PopupHeader } from 'vux';
  const baseList = [{
    url: 'javascript:',
    img: 'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/banner1.png',
    title: ''
  },
    {
    url: 'javascript:',
    img: 'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/banner2.png',
    title: ''
  },
    {
    url: 'javascript:',
    img: 'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/banner3.png',
    title: '',
  }];
  const urlList = baseList.map((item, index) => ({
    url: 'http://m.baidu.com',
    img: item.img,
    fallbackImg: item.fallbackImg,
    title: `${item.title}`
  }));

  export default {
    components: {
      XHeader, Swiper, vTitle, Flexbox, FlexboxItem, Tab, TabItem, Grid, GridItem, vDetail, Popup, PopupHeader, vStore
    },
    data () {
      return {
        demo06_list: urlList,
        demo06_index: 0,
        isStore:false,
        iconList:[
          {
            img:'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/index_01.png',
            text:'新鲜蔬菜',
            url:'/project1/view1/goods'
          },
          {
            img:'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/index_02.png',
            text:'时令水果',
            url:'/project1/view1/goods'
          },
          {
            img:'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/index_03.png',
            text:'水产生鲜',
            url:'/project1/view1/goods'
          },
          {
            img:'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/index_04.png',
            text:'米面粮油',
            url:'/project1/view1/goods'
          },
          {
            img:'http://dlhz.oss-cn-beijing.aliyuncs.com/supply-app-img/index_05.png',
            text:'休闲食品',
            url:'/project1/view1/goods'
          },
        ],
        tabList:[],
        goodsList:[],
        isShow:false,
        tabIndex:-1,
        isShowDetail:false,
        goodsId:'',

        showPositionValue: false, // Toast提示
        position: 'default',
        toastMsg: '',
      }
    },
    created(){
      this.getIndexGoods()
      $(".child-view").css({overflow:'scroll'})
    },
    methods:{
      // 查看更多
      toMore(){
        this.$router.push('/project1/view1/class')
      },
      // 获取首页商品
      getIndexGoods(){
        this.$vux.loading.show({
          text: 'Loading'
        });
        this.config1.post('/purchasers/app/goods/findByGoodsClassification', {}).then(res=>{
          if(res.data.code==0){
            this.$vux.loading.hide();
            this.tabList = res.data.GoodsClassificationList;
            this.goodsList = res.data.GoodsClassificationList
            this.isShow = true
          }else{
            this.msg(res.data.message);
          }
        }).catch(err=>{
          this.$vux.loading.hide();
          this.msg('网络错误');
        })
      },
      toShop(text){
        this.text = text
        this.type = 0
        this.isStore = true
      },
      back1(msg){
        this.isStore = msg
      },
      // 点击选项卡
      changeTab(type,item){
        if(type){
          this.goodsList = this.tabList
          return
        }
        this.goodsList = []
        this.goodsList.push(item)
      },
      // 查看商品详情
      showDetail(goods){
        this.isShowDetail = true
        this.goodsId = goods.id
      },
      back(msg){
        this.isShowDetail = msg
      },
      // 轮播图
      demo06_onIndexChange (index) {
        this.demo06_index = index
      },
      // 信息提示
      msg(str){
        this.showPositionValue = true;
        this.position = 'middle';
        this.toastMsg = (str);
      },
    }
  }
</script>
<style scoped lang="less">
  @import "../../../assets/css/font_975465_4qn59qnejbp/iconfont.css";
  *{
    font-family: 微软雅黑;
  }
  ul li{
    list-style-type: none;
  }
  img{
    width: 100%;
  }
.index-top{
  position: relative;
}
.index-bg{
  position: absolute;
}
.index-banner{
  width:93%;
  margin: 10px auto 0;
  border-radius: 5px;
  overflow: hidden;
  box-shadow: 2px 2px 8px #c2c2c2;
}
.icon-nav{
  padding: 20px 0 10px;
}
.icon-nav-item{
  width:20%;
  display: inline-block;
  text-align: center;
  font-size: 0.8rem;
  color: #000;
}
  .icon-nav-item img{
    width:70%;
  }
  .bargain-sale{
    padding-bottom: 5px;
  }
  .flex-demo{
    height:100%;
    border-radius: 5px;
    box-shadow: 0px 0px 6px #c5c5c5;
  }
  .flex-title{
    padding:5px 0 0 5px;
  }
  .flex-text{
    font-size: 0.7rem;
    padding-left:5px;
  }
  .flex-btn{
    line-height:20px;
    background: #33bb99;
    display: inline-block;
    padding:0 7px;
    border-radius: 5px;
    color:#fff;
    margin: 5px 0 5px 5px;
  }
  .flex-btn.right{
    margin: 15px 0 15px 5px;
  }
  .right-item{
    background: url("../../../assets/images/img_03.png") right bottom no-repeat;
    background-size: 100% 100%;
  }
  .right-item2{
    background: url("../../../assets/images/img_01.png") right bottom no-repeat;
    background-size: 100% 100%;
  }
  .right-item0{
    height:198px;
    background: url("../../../assets/images/img_02.png") center bottom no-repeat;
    background-size: 100% 100%;
  }
  .goods-item{
    background: #fbf9fe;
    clear: both;
  }
  .goods-item-title{
    padding: 0 0.5rem;
    font-size:0.8rem;
    line-height:2rem;
    color:#000;
    .title{
      border-left:2px #33bb99 solid;
      font-weight: 700;
      line-height:20px;
      padding-left: 7px;
      display: inline-block;
      /*float: left;*/
    }
    .more{
      float: right;
      color:#33bb99;
      display: inline-block;
    }
  }
  .goods-text{
    clear: both;
    .search-item{
      width: 50%;
      margin: 0.5rem 0;
      display: inline-block;
      .item-text{
        width: 93%;
        background: #fff;
        margin:0 auto;
        overflow: hidden;
        border-radius: 5px;
        box-shadow: 0 0 8px #e1e1e1;
        line-height: 2rem;
        .item-img{
          height:150px;
          img{
            height:100%;
            width:100%;
          }
        }
        p{
          font-size: 0.8rem;
          display: block;
          white-space: nowrap;
          width: 90%;
          margin: 0 auto;
          overflow: hidden;
          text-overflow:ellipsis;
        }
        .item-tip{
          padding:0 0.5rem;
          .iconfont{
            color:#33bb99;
            float: right;
          }
          span{
            color: #999;
            font-size: 0.6rem;
          }
        }
        .item-address{
          font-size: 0.6rem;
          display: block;
          line-height:1.5rem;
          white-space: nowrap;
          /*width: 90%;*/
          /*margin: 0 auto;*/
          overflow: hidden;
          text-overflow:ellipsis;
          .iconfont{
            color:#33bb99;
            padding:0 0.2rem 0 0.3rem;
          }
        }
      }
    }
  }

</style>
